package com.chihihx.launcher.ui.viewmodel

import android.os.Build
import com.chihihx.launcher.bean.HomeInfoDto
import com.chihihx.launcher.net.UrlManager
import io.github.lib_autorun.bean.UpdateDto
import io.github.lib_autorun.ext.NetCache.channel
import io.github.lib_autorun.ext.appVersionCode
import io.github.lib_autorun.ext.getDeviceAndAppInfo
import io.github.lib_autorun.ext.getMacAddress
import io.github.lib_autorun.ext.getUniqueDeviceId
import io.github.lib_autorun.net.NetworkHelper
import io.github.lib_autorun.net.enum.RequestMethod
import com.nova.android.tvlauncher.BuildConfig
import com.shudong.lib_base.ext.appContext
import com_github_lib_base.base.BaseViewModel

class MainViewModel: BaseViewModel() {
    fun getHomeInfo(callback: (HomeInfoDto?) -> Unit) {
        NetworkHelper.makeRequest(
            UrlManager.HOME_INFO,
            RequestMethod.GET,
            mapOf(
                "req_id" to "0",
                "channel" to BuildConfig.CHANNEL,
                "launch_type" to 0,
                /*"version" to appContext.appVersionCode(),
                "sdk" to Build.VERSION.SDK_INT.toString(),
                "uuid" to appContext.getUniqueDeviceId(),
                "brand" to Build.BRAND,
                "product" to Build.PRODUCT,
                "mac" to (getMacAddress() ?: ""),
                "extra_params" to appContext.getDeviceAndAppInfo(),*/
            ),
            isForm = true,
            isEncryted = false
        ) { dto: HomeInfoDto?, error: Throwable? ->
            if (error == null) {
                dto?.let {
                    // 完成请求，返回结果
                    callback.invoke(dto)
                }

            } else {
                callback.invoke(null)
            }
        }
    }
}